/**
 * 
 */
package com.jm.web.builder.table;

import java.io.IOException;

import com.jm.utils.StringBuilderEx;
import com.jm.utils.StringHelper;
import com.jm.web.builder.BaseBuilder;
import com.jm.web.tags.support.BaseTag;
import com.jm.web.tags.table.TbodyTag;

/**
 * @author yanjie
 *
 * 2011/9/23 上午8:46:52
 */
public class TbodyBuilder extends BaseBuilder{
	protected TbodyTag tbodyTag = null;
	protected boolean bfirst = true;
	
	@Override
	public void init(BaseTag tag) {
		super.init(tag);
		tbodyTag = (TbodyTag)tag;
	}
	
	@Override
	public void RenderStart() {
		if(bfirst){
			StringBuilderEx sb = new StringBuilderEx();
			sb.Append("<tbody ");
			
			if(!StringHelper.IsNullOrEmpty(this.getBaseTag().GetExtValue("class",""))){
				sb.Append(" class = \"listing-tbody %1$s\" ",this.getBaseTag().GetExtValue("class",""));
			}else{
				sb.Append(" class=\"listing-tbody\"");
			}
			
			if(!StringHelper.IsNullOrEmpty(this.getBaseTag().GetExtValue("style",""))){
				sb.Append(" style = \"%1$s\" ",this.getBaseTag().GetExtValue("style",""));
			}
			
			if(!StringHelper.IsNullOrEmpty(this.getBaseTag().GetExtValue("id",""))){
				sb.Append(" id = \"%1$s\" ",this.getBaseTag().GetExtValue("id",""));
			}
			
			if (!StringHelper.IsNullOrEmpty(this.getBaseTag().GetExtValue("extAtr",""))){
				sb.Append(" %1$s",
						this.getBaseTag().GetExtValue("extAtr",""));
			}
			sb.Append(" >");
			
			try {
				this.getOut().write(sb.toString());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else{
			bfirst = false;
		}
	}
	
	@Override
	public void RenderEnd() {
		if(bfirst){
			StringBuilderEx sb = new StringBuilderEx();
			sb.Append("</tbody>");
			try {
				this.getOut().write(sb.toString());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else{
			bfirst = false;
		}
	}
}
